<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%-- 使用taglib指令导入jstl标记 --%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%> 
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JSTL操作数据库</title>
</head>
<body>
<!-- 1.设置数据源，连接数据库 -->
<sql:setDataSource var="source" driver="com.mysql.cj.jdbc.Driver" url="jdbc:mysql://localhost:3306/niit?serverTimezone=Asia/Shanghai&useSSL=false&characterEncoding=utf8" user="root" password="root"></sql:setDataSource>


<h1>1.查询</h1>
<sql:query var="result" dataSource="${source}">
	select * from book;
</sql:query>
<table border="1">
	<tr>
		<th>序号</th>
		<th>编号</th>
		<th>名称</th>
		<th>作者</th>
		<th>单价</th>
	</tr>
	<c:forEach items="${result.rows}" var="bookItem">
		<tr>
			<td>${bookItem.id}</td>
			<td>${bookItem.code}</td>
			<td>${bookItem.name}</td>
			<td>${bookItem.author}</td>
			<td>${bookItem.unit_price}</td>
		</tr>
	</c:forEach>
</table>


</body>
</html>